//
//  NBBaseViewController.swift
//  NBSinaWeibo
//
//  Created by ac on 16/5/20.
//  Copyright © 2016年 ac. All rights reserved.
//

import UIKit

class NBBaseViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.interactivePopGestureRecognizer?.delegate = self
        
        
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        let backTitle = childViewControllers.count == 1 ? childViewControllers.first?.title ?? "返回" : "返回"
        let backBtn = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backTitle, target: self, action: #selector(popVC))
        if childViewControllers.count > 0 {
            viewController.navigationItem.leftBarButtonItem = backBtn
        }
        
        super.pushViewController(viewController, animated: animated)
        
        
    }
    
    
    
    @objc private func popVC(){
        popViewControllerAnimated(true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        if childViewControllers.count > 1 {
            return true
        }
        return false
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
